package com.hfzy.ihk.web.freeswitchCall.support;

import com.hfzy.ihk.web.freeswitchCall.constant.RedisKey;
import com.hfzy.ihk.web.freeswitchCall.utils.CallHistoryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Administrator on 2016/5/27.
 * @author wws
 *
 * 简单数据缓存
 */
@Component
public class SampleMemoryCache {
    private final static Logger logger = LoggerFactory.getLogger(SampleMemoryCache.class);

    private static RedisTemplate<String, Object> redisTemplate;

    @Autowired
    public void setRedisTemplate(RedisTemplate redisTemplate) {
        SampleMemoryCache.redisTemplate = redisTemplate;
    }

    /**网关注册信息
     * sipUser: "@ip:port"
     * */
    public static volatile ConcurrentHashMap<String,String> gatewayContrcatInfo = new ConcurrentHashMap<>(100);

    public static volatile ConcurrentHashMap<String,Boolean> sessionInterruptMap = new ConcurrentHashMap<>(1000);

    /**投诉我们的客户号码，这类号码不允许再呼出*/
    public static volatile ConcurrentHashMap<String, String> badCustomerPhoneMap = new ConcurrentHashMap<>(100);

    public static boolean isBadCustomerPhone(String customerPhone){
//     久逻辑先注释
//        if(badCustomerPhoneMap.containsKey(customerPhone)){
//            return true;
//        }
//        return false;
        //新版逻辑，将原来放在set的号码转存到map中
        try {
            Object state = redisTemplate.opsForHash().get(RedisKey.BAD_CUSTOMER_PHONE_Map, customerPhone);
            if (state == null)
                return false;
            if ("1".equals(state.toString())) {
                return true;
            }
            return false;
        }catch (Exception e){
            return false;
        }
    }

}
